/*!
 * 通用开启消息通知模块
 */
define( [ 'jquery', 'message', 'constants' ], function( $, ShowTitleMessage, c ) {
  return function( userlogin ) {
    if ( !userlogin || typeof GoEasy === 'undefined' ) return false;

    /* eslint-disable no-undef */
    var goEasy = new GoEasy( {
      appkey: 'b7fb4e5f-98e4-4f9b-98d4-56ea2302158e'
    } );
    // if ( window.localStorage.getItem( userlogin + '_notice' ) == 1 && $( '#frm_header #page_id' ).val() != 'TLM018' ) {
    // 	$( '#user_notice' ).addClass( 'notice_show' );

    // } else {
    // 	window.localStorage.removeItem( userlogin + '_notice' );
    // 	if ( window.opener ) {
    // 		try {
    // 			$( '#user_notice', window.opener.document.body ).removeClass( 'notice_show' );
    // 		} catch ( e ) {}
    // 	}
    // }
    /* $( '.notice_newest' ).click( function( e ) {
      e.preventDefault();
    } );
    $( '.notice_newest .notice_text' ).click( function() {
      window.open( '/notice', 'notice' );
    } ); */
    $( '.notice_newest .shut' ).click( function() {
      $( this ).parent( '.notice_newest' ).fadeOut();
    } );
    window.localStorage.setItem( 'IsNotice', 1 );
    goEasy.subscribe( {
      channel: userlogin + '_channel',
      onMessage: function( message ) {
        var json = typeof message.content == 'object' ? message.content : $.parseJSON( message.content );
        var noticeType = false;
        var ua = navigator.userAgent.toLowerCase();
        $( '.user_notice .icon-tongzhi' ).hide();
        $( '.user_notice .num' ).css( 'display', 'inline-block' );
        localStorage.notice_num++;
        $( '.top_main_nav .user_notice .num' ).text( localStorage.notice_num );
        if ( c.pageID === 'TLM018' || json.select === c.pageID ) {
          window.location.reload();
        } else {
          window.localStorage.setItem( userlogin + '_notice', 1 );
        }
        if ( ua.indexOf( 'firefox' ) > -1 || ua.indexOf( 'edge' ) > -1 ) {
          noticeType = true;
        }

        if ( window.localStorage.getItem( 'IsNotice' ) == 1 ) {
          ShowTitleMessage.notice( json.title );
          window.localStorage.setItem( 'IsNotice', 0 );
          setTimeout( "window.localStorage.setItem('IsNotice', 1)", 1e3 );
        }
      }
    } );

    return true;
  }
} );
